package com.jalarbee.core.jpa;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo;
import org.springframework.orm.jpa.persistenceunit.PersistenceUnitPostProcessor;

public class CustomPersistenceUnitPostProcessor implements
		PersistenceUnitPostProcessor {

	protected static final Logger logger = Logger.getLogger(CustomPersistenceUnitPostProcessor.class);
	Map<String,List<String>> puiClasses = new HashMap<String, List<String>>();
	

	@Override
	public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui) {
		logger.info(pui);
		logger.info(pui.getPersistenceUnitName());
		
		List<String> classes = puiClasses.get(pui.getPersistenceUnitName());
		if (classes == null)
		{
			classes = new ArrayList<String>();
			puiClasses.put(pui.getPersistenceUnitName(), classes);
		}
		pui.getManagedClassNames().addAll(classes);
		
		classes.addAll(pui.getManagedClassNames());


		logger.info(Arrays.toString(pui.getManagedClassNames().toArray(new String[0])));
	}

}
